<?php

if (!empty($serviceUnitList)) {
    $this->Paginator->options(array(
        'update' => '#divUpdate',
        'evalScripts' => true,
    ));

    $pageNo = $this->Paginator->current('ServiceUnit');    
}

$page_params = $this->Paginator->params();
$limit = $page_params['limit'];

echo $this->session->flash();
?>
<div class="file">
    <table width="100%" border="0" cellspacing="1" cellpadding="2" bgcolor="#686550">
        <tr class="heading">
            <td width="5%" valign="top" bgcolor="#708089"><?php echo __('S.NO'); ?></td>
            <td valign="top" bgcolor="#708089"><?php echo $this->Paginator->sort('unit_code', __('UNIT_CODE', true)); ?></td>
            <td valign="top" bgcolor="#708089"><?php echo $this->Paginator->sort('unit_name', __('UNIT_NAME', true)); ?></td>
            <td valign="top" bgcolor="#708089"><?php echo __('ACTION') ?></td>
        </tr>

        <?php
        if (isset($serviceUnitList) && ($serviceUnitList != "")) {
            $i = 0;
            foreach ($serviceUnitList as $arrayDetail) {
                ?>
                <tr>
                    <td bgcolor="#FFFFFF"><?php echo $i + 1 ?></td>
                    <td bgcolor="#FFFFFF"><?php echo $arrayDetail['ServiceUnit']['unit_code'] ?></td>
                    <td bgcolor="#FFFFFF"><?php echo $arrayDetail['ServiceUnit']['unit_name'] ?></td>
                    <td bgcolor="#FFFFFF">&nbsp;<?php
                        if(in_array($arrayDetail['ServiceUnit']['id'], $allocatedUnitList)){
                            echo $this->Js->link(
                                $this->Html->image('saas-images/status.gif'), 
                                array(
                                    'controller' => 'users',
                                    'action' => 'revoke_unit', $user_id, array_search ($arrayDetail['ServiceUnit']['id'], $allocatedUnitList), $pageNo, $limit
                                ), 
                                array(
                                    'update' => '#divUpdate',
                                    'alt' => __('DELETE', true),
                                    'title' => __('DELETE', true),
                                    'escape'=>false,
                                    'before' => $this->Js->get('#divUpdate')->effect('fadeOut'),
                                    'success' => $this->Js->get('#divUpdate')->effect('fadeIn')
                                )
                            );
                        } else{
                            echo $this->Js->link(
                                $this->Html->image('saas-images/forbidden.gif'), 
                                array(
                                    'controller' => 'users',
                                    'action' => 'allow_unit', $user_id, $arrayDetail['ServiceUnit']['id'], $pageNo, $limit 
                                ), 
                                array(
                                    'update' => '#divUpdate',
                                    'alt' => __('DELETE', true),
                                    'title' => __('DELETE', true),
                                    'escape'=>false,
                                    'before' => $this->Js->get('#divUpdate')->effect('fadeOut'),
                                    'success' => $this->Js->get('#divUpdate')->effect('fadeIn')
                                )
                            );
                        }
                    ?>
                    </td>
                </tr>  
                <?php
                $i++;
            }
        }
        if (empty($serviceUnitList)) {
            ?>
            <tr>
                <td bgcolor="#FFFFFF" colspan="4" align="center">
                    <?php
                    echo __("NO_RECORD_MESSAGE", true);
                    ?>
                </td>
            </tr>
            <?php
        } else {
            ?>
            <tr>
                <td colspan="8" bgcolor="#ffffff">
                    <div class="pagination">
                        <ul>
                            <li>
                                <?php
                                echo $this->Element('pagination_unit_list');
                                ?>
                            </li>

                        </ul>
                    </div>
                </td>
            </tr>

        <?php }
        ?>

        <tr bgcolor="#ffffff">
            <td colspan="4" valign="top">
                <table width="70%">
                    <tr>
                        <td width="10%">
                            <b><?php echo __('LEGENDS'); ?> :- </b> 
                        </td>
                        <td width="15%">
                            <?php echo $this->html->image('/img/icons/16/edit_user.png'); ?>

                            <?php echo __('EDIT_USER'); ?>
                        </td>
                        <td width="15%">
                            <?php echo $this->html->image('/img/icons/16/permissions.png'); ?>

                            <?php echo __('EDIT_UNIT_PERMISSION'); ?>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>

    </table>

</div>
<?php echo $this->Js->writeBuffer(); ?>